import Character
import pygame

class BodyPart(Character.Character):
	def __init__(self,x,y,mass,holes,image):
		Character.Character.__init__(self,x=x,y=y,mass=mass)
		self.image=image
		self.holes=holes
		self.dead=True
		self.generate_currs()
	def generate_currs(self):
		import math
		#if (self.prev_y==self.y and self.prev_x==self.x):
		if (self.x-self.prev_x)**2+(self.y-self.prev_y)**2==0:
			a=0
		else:
			#print (self.x-self.prev_x)**2,(self.y-self.prev_y)**2,((self.x-self.prev_x)**2+(self.y-self.prev_y)**2)**0.5
			r=(self.x-self.prev_x)/(((self.x-self.prev_x)**2+(self.y-self.prev_y)**2)**0.5)
			a=math.acos(r)*180/math.pi
			if self.y-self.prev_y<0:
				a=-a
		self.cur_angle=a
		if a!=0:
			b=a*math.pi/180.0
			self.cur_image=pygame.transform.rotate(self.image,self.cur_angle)
			c_holes=[]
			for hole in self.holes:
				h=[hole[0]*math.cos(b)-hole[1]*math.sin(b),hole[0]*math.sin(b)+hole[1]*math.cos(b)]
				c_holes.append(h)
			self.cur_holes=c_holes
		else:
			self.cur_holes=self.holes
			self.cur_image=self.image
	def bumping(self):
		#return True
		eps=10
		return True#not (-eps<=self.x-self.prev_x<=eps and -eps<=self.y-self.prev_y<=eps)
		#return False
	def drawingInformation(self):
		return (self.x-0.5*self.getWidth(),self.y+self.getHeight()),self.cur_image
	def getWidth(self):
		return self.cur_image.get_width()
	def getHeight(self):
		return self.cur_image.get_height()
	def process(self):
		self.generate_currs()
		Character.Character.process(self)